package com.hwhp.web.console.servlet;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hwhp.entity.YzUser;
import com.hwhp.service.console.UserService;
import com.hwhp.service.console.impl.UserServiceImpl;



public class LoginDepartSelectAjax extends HttpServlet{
	private UserService userService = new UserServiceImpl(); ;
	
	public LoginDepartSelectAjax() {
		super();
	}
 
	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		String departmentid = request.getParameter("departmentid");
		String rtn="";
		String rtx="";
		try{
		 List<YzUser> userList=new ArrayList();
		 String returnXML = "<?xml version=\"1.0\" encoding=\"GBK\"?><root>";
		 if(departmentid!=null&&!"".equals(departmentid)){
			 userList=userService.queryUserByDeptId(departmentid);
		 for(YzUser userObj:userList){
			 returnXML=returnXML+"<node attr=\""+userObj.getUserName()+"\" value=\""+userObj.getUserId()+"\"></node>";
		 }
		 }
		 returnXML=returnXML+"</root>";
		response.setHeader("Content-Type", "text/xml; charset=GBK");
		PrintWriter out = response.getWriter();
		out.print(returnXML);
		out.flush();
		out.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) {
		this.doGet(request, response);
	}

	public void destroy() {
		super.destroy();
	}

//	public void setUserService(UserService userService) {
//		this.userService = userService;
//	}
//
//	public UserService getUserService() {
//		return userService;
//	}
}
